package com.bdqn.vueboot.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bdqn.vueboot.config.R;
import com.bdqn.vueboot.dto.SuppliesDto;
import com.bdqn.vueboot.entity.Supplies;
import com.bdqn.vueboot.service.SuppliesService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 办公物品申领(Supplies)表控制层
 *
 * @author makejava
 * @since 2022-12-03 09:09:36
 */
@RestController
@RequestMapping("supplies")
@CrossOrigin
public class SuppliesController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private SuppliesService suppliesService;


    @GetMapping("/list")
    public R list(@RequestParam(value = "pageIndex", required = false, defaultValue = "1") Integer pageIndex,
                  @RequestParam(value = "limit", required = false) Integer limit,
                  @RequestParam(value = "suppliesName", required = false) String suppliesName
    ) {
        IPage<Supplies> page = new Page(pageIndex, limit);

        SuppliesDto supplies = new SuppliesDto();
        supplies.setSuppliesName(suppliesName);
        IPage<SuppliesDto> page1 = suppliesService.pages(page, supplies);
        return R.success(page1);
    }

    @RequestMapping("/deleteById")
    public R deleteById(@RequestParam(value = "suppliesId", required = false, defaultValue = "1") Long suppliesId) {
        int i = suppliesService.deleteById(suppliesId);
        if (i > 0) {
            return R.success(i);
        } else {
            return R.error("修改失败");
        }
    }
    @RequestMapping("/add")
    public R add(@RequestBody Supplies supplies) {
        int i=suppliesService.add(supplies);
        if(i>0){
            return R.success(i);
        }else{
            return R.error("添加失败！");
        }

    }

}

